package com.hhkj.api.withdrawal.controller;

import com.hhkj.api.sale.common.session.model.LoginSale;
import com.hhkj.api.withdrawal.model.req.ApiWithdrawalPagingReq;
import com.hhkj.api.withdrawal.model.req.ApiWithdrawalSaveReq;
import com.hhkj.api.withdrawal.service.biz.ApiSaleWithdrawalBizService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.framework.login.api.ApiLogin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * ApiSaleWithdrawalController
 *
 * @author zheng
 * @since 2023/11/7 0:57
 */
@RestController
@RequestMapping("/api/sale/withdrawal")
public class ApiSaleWithdrawalController extends BaseController {

    @Autowired
    private ApiSaleWithdrawalBizService withdrawalBizService;

    /** 新增提现 */
    @ApiLogin(LoginSale.class)
    @PostMapping()
    public AjaxResult save(@Validated @RequestBody ApiWithdrawalSaveReq req) {
        return withdrawalBizService.save(req) ? AjaxResult.success() : AjaxResult.error();
    }

    /** 统计今天提现次数 */
    @ApiLogin(LoginSale.class)
    @GetMapping("/current/day/amount/count")
    public AjaxResult countAmountCurrentDay() {
        return AjaxResult.success(withdrawalBizService.countAmountCurrentDay());
    }

    /** 获取提现详情 */
    @ApiLogin(LoginSale.class)
    @GetMapping("/{id}")
    public AjaxResult getById(@PathVariable("id") Long id) {
        return AjaxResult.success(withdrawalBizService.getById(id));
    }

    /** 分页 */
    @ApiLogin(LoginSale.class)
    @PostMapping("/paging")
    public TableDataInfo paging(@RequestBody ApiWithdrawalPagingReq req) {
        startPageBody(req);
        return getDataTable(withdrawalBizService.paging(req));
    }
}
